# -*- coding: utf-8 -*-

<%page cached="True" cache_type="memory" cache_key="${c.cache_key}"/>

## We need the javascript forms stuffs for dynamic loaded elements:
<%inherit file="/base_form.mako"/>

<%namespace name="student_comps" file="/students/components.mako"/>
<%namespace name="room_comps" file="/rooms/components.mako"/>

<%def name="javascript()">
    ${parent.javascript()}
    ${self.javascript_link('jquery', 'jquery.quicksearch.js', 'ping', 
                           'validation/editstudent', 'table')}
</%def>

<%def name="css()">
	${parent.css()}
	${self.css_link('table')}
	${self.css_link('studentdetail')}
</%def>

<h1>
Students
</h1>

<table id="table_students">
	<thead>
	<tr>
		<th>Firstname</th>
		<th>Lastname</th>
		<th>Email</th>
		<th>Username</th>
		<th>Room</th>
		<th>Groups</th>
	</tr>
	</thead>
	
<%def name="line_for_student_inside(student)">
    <td>
        ${student_comps.link_to(student, 'firstname')|h}
    </td>
    <td>
        ${student_comps.link_to(student, 'lastname')|h}
    </td>
      <td>
        ${student_comps.link_to(student, 'email')|h}
    </td>
    <td>
      ${student_comps.link_to(student, 'username')|h}
    </td>
    <td>
      ${room_comps.link_to(student.room)}
    </td>
    <td>
          ${", ".join([g.name for g in student.groups]) or "-"|h}
      </td>
</%def>	

<%def name="line_for_student(student)" cached="True" cache_type="memory" 
      cache_key="student_${str(student.id)}">
  <tr class="student_row" id="student_row_${str(student.id)}">
      ${self.line_for_student_inside(student)}
  </tr>
</%def>

  %for student in c.students_q.all():
    ## TODO: only query ids of students, or make the student object fully lazy?
  	${line_for_student(student)}
  %endfor
  </table>
  
  <div id="student_box">
  
  </div>
